package DMSXL._2023Before.Array;

public class Biearch {
    public static void main(String[] args) {
        int[] nums = {-1,0,3,5,9,12};
        int target = 2;

        System.out.println(search(nums,target));
    }
    public static int search(int[] nums, int target) {
        int first = 0;
        int last = nums.length - 1;
        int middle = (first + last) / 2;
        while(first <= last){
            if(nums[middle] == target){
                return middle;
            }
            else if(nums[middle] > target){
                last = middle - 1;
            }
            else
            {
                first = middle + 1;
            }
            middle = (first + last) / 2;
        }
        return -1;
    }


}
